/*
 *  SPAGL Copyright (C) 2008 Sam Pottinger
 *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser 
 *  General Public License as published by the Free Software Foundation; either version 2.1 of the License, or 
 *  (at your option) any later version. This library is distributed in the hope that it will be useful, but 
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 *  See the GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License along with this library; if not, 
 *  write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 */

package spagswing;

import java.util.ArrayList;
import spagcore.SpaglCoreApp;
import spagcore.SpaglCoreWindow;
import spagswt.SpaglWindow;

/**
 * An object to represent a swing application that complies with the SPAGL core app interface
 * @author Sam Pottinger
 */
public class SpaglApp implements SpaglCoreApp {
	
	private ArrayList<SpaglCoreWindow> windows = new ArrayList<SpaglCoreWindow>(0);
	private SpaglWindow root;

	/**
	 * Creates a simple bare bones application
	 */
	public void addWindow(SpaglCoreWindow newWindow) {
		
		windows.add(newWindow);
		
	}
	
	/**
	 * Sets the applications "root window" that when closed will terminate the application
	 * 
	 * @param newRoot the window to be the root window
	 */
	public void setRootWindow(SpaglWindow newRoot)
	{
		root = newRoot;
	}
	
	/**
	 * Closes all of the windows in the application
	 */
	public void close() {
		
		for(SpaglCoreWindow window : windows)
			window.dispose();
		
	}

	/**
	 * Gets the windows associated with this application
	 * 
	 * @return An array of {@link SpaglWindow}s as {@link SpaglCoreWindow}s
	 */
	public SpaglCoreWindow[] getWindows() {
		
		return (SpaglCoreWindow[])windows.toArray();
		
	}

	/**
	 * Begins the event loop
	 * <br><br>Note: swing does not need an event loop so it is here for cross library purposes
	 */
	public void startEventLoop() {
		// Swing does not need to use an event loop
	}
	
	/**
	 * Gets the root window for the application
	 * 
	 * @return Returns a native {@link SpaglWindow}
	 */
	public SpaglWindow getRoot()
	{
		return root;
	}

}
